package com.idea.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * 合同主表
 *
 * @author lajiaochaorou
 * ClassName Contract
 * @data 2022/12/2  9:57
 **/
@Data
public class ContractDTO implements Serializable {

    private String id;

    /**
     * 合同名称
     */
    private String contractName;

    private Date effectiveDate;

    private Date beginBuildUpPeriod;
    private Date enndBuildUpPeriod;

    private Date beginTermsEffectiveDate;
    private Date endTermsEffectiveDate;

    private Date beginBuildDownPeriodDate;
    private Date endBuildDownPeriodDate;


    private String customerName;

    /**
     * 租赁类型
     */
    private String leaseType;

    /**
     * 新旧箱
     */
    private String equipmentCondition;

    /**
     * 国家
     */
    private String currency;

    /**
     * 提箱明细
     */
    private List<ContainerDTO> containers = new ArrayList<>();

    /**
     * 最大列数
     */
    @JsonIgnore
    private Integer colMaxEndIndex;


    /**
     * 获取当前合同Excel文件的最大列下标
     *
     * @return
     */
    public int getColMaxEndIndex() {
        if (this.colMaxEndIndex != null) {
            return this.colMaxEndIndex;
        }

        if (containers != null) {
            int tempColMaxEndIndex = 0;
            for (ContainerDTO containerDTO : containers) {
                tempColMaxEndIndex += containerDTO.getRightColSumCount();
            }
            this.colMaxEndIndex = tempColMaxEndIndex + 1;
        }
        return this.colMaxEndIndex;
    }

    /**
     * 计算当前合同最多的提箱地点行数
     *
     * @return
     */
    public int getPickupMaxRowCount() {
        if (containers == null) {
            return 0;
        }
        return this.getContainers().stream().max(Comparator.comparing(ContainerDTO::getPickupSize)).get().getPickupSize();
    }


}
